package com.dnzx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.dnzx.framework.page.PageResult;
import org.springframework.stereotype.Service;

import com.dnzx.dao.IProductDao;
import com.dnzx.model.ProductBO;
import com.dnzx.service.IProductService;

/**
 * 订单
 */
@Service
public class ProductServiceImpl implements IProductService {

    @Resource
    private IProductDao productDao;

    @Override
    public void save(ProductBO productBO) throws Exception {
        this.productDao.save(productBO);
    }

    @Override
    public void delete(Long id) throws Exception {
        this.productDao.delete(id);
    }

    @Override
    public void update(ProductBO productBO) throws Exception {
        this.productDao.update(productBO);
    }

    @Override
    public ProductBO get(Long id) {
        return this.productDao.get(id);
    }
    
    @Override
    public ProductBO get(ProductBO productBO) {
    	List<ProductBO> productBOList = this.productDao.queryList(productBO);
    	if (productBOList != null && productBOList.size() > 0) {
    		return productBOList.get(0);
    	}
        return null;
    }
    
    @Override
    public List<ProductBO> queryList(ProductBO productBO) {
        return this.productDao.queryList(productBO);
    }
    
    @Override
    public PageResult<List<ProductBO>> queryPage(ProductBO productBO, PageResult<List<ProductBO>> pageResult) {
        int totalRows = this.productDao.queryCount(productBO);
        pageResult.setTotalRows(totalRows);
        pageResult.setCurrentPage(productBO.getCurrentPage());
        pageResult.setPageSize(productBO.getPageSize());
		List<ProductBO> records = this.productDao.queryPage(pageResult.getPageSize(), pageResult.getStartRow(), productBO);
		pageResult.setT(records);
		return pageResult;
    }

}
